package com.example.myapplication.jet;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.SavedStateHandle;
import androidx.lifecycle.ViewModel;

public class UserViewModel extends ViewModel {


//    private MutableLiveData<Integer> liveData;
    private SavedStateHandle handle;

    public UserViewModel(SavedStateHandle handle) {
        this.handle = handle;
    }


    public MutableLiveData<Integer> getLiveData() {
        if (!handle.contains("NUMBER")) {
            handle.set("NUMBER", 0);
        }
        /*if (liveData == null) {
            liveData = new MutableLiveData<>();
            liveData.setValue(0);
        }*/
        return handle.getLiveData("NUMBER");
    }

    public void add() {
        handle.set("NUMBER", (Integer) handle.getLiveData("NUMBER").getValue() + 1);
    }
}
